import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/22 10:16
 * @description 前缀和
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int maxRotateFunction(int[] nums) {
        int sum = 0 , o = 0;
        int n = nums.length;
        // 初始化 sum 和 F[0] = o
        for(int i = 0;i < n;i ++) {
            o += nums[i] * i ;
            sum += nums[i];
        }
        int res = o;
        // F[i] = F[i-1] + sum - n * nums[n - i]
        for(int i = 1;i < n;i ++) {
            o = o + sum - n * nums[n - i];
            res = Math.max(res, o);
        }
        return res;

    }
}
